/*
 * Created: Author: Aléx Carvalho / Date: Jan 24, 2015
 * 
 * Changed: $Author: ac280593@gmail.com $ / $Date: 2015-06-04 21:21:41 -0300 (Thu, 04 Jun 2015) $
 */
package com.cpm.view.zk.buttons;

import com.cpm.view.Element;
import com.cpm.view.Icon;
import org.zkoss.zk.ui.HtmlBasedComponent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;

public class Button implements Element<HtmlBasedComponent> {

    private final org.zkoss.zul.Button button = new org.zkoss.zul.Button();

    public void setText(String text) {
        button.setLabel(text);
    }

    public void setIcon(Icon icon) {
        button.setIconSclass(icon.getIconClass());
    }

    public void setTooltip(String tooltip) {
        button.setTooltiptext(tooltip);
    }

    public void setVisible(boolean visible) {
        button.setVisible(visible);
    }

    public boolean isVisible() {
        return button.isVisible();
    }

    public void setEnabled(boolean enable) {
        button.setDisabled(!enable);
    }

    public boolean isEnabled() {
        return !button.isDisabled();
    }

    public void addEventListener(String event, EventListener eventListener) {
        if (eventListener != null) {
            button.addEventListener(event, (Event t) -> eventListener.onEvent(t));
        }
    }

    @Override
    public HtmlBasedComponent getElement() {
        return button;
    }
}
